﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
   <#include "../comm/header.ftl"/>
    <link href="${req.contextPath}/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="${req.contextPath}/js/bootstrap/css/bootstrap.css" type="text/css" />
    <script>
        var grid = null;//表格对象
        $(function () {
            //grid
            grid = $("#department_msg").ligerGrid({
                height: '100%',
                heightDiff: -5,
                root:'list',
                record:'total',
                pageParmName:'currentPage',
                pagesizeParmName:'pageSize',
                dataAction: 'server',
                url: '/employee/getEmployeeData.do',
                checkbox:true,
                rownumbers:true,
                columns: [
                    {display: 'id', name: 'id',hide:true},
                    {display: 'sid', name: 'sid'},
                    {display: '姓名', name: 'name'},
                    {display: '性别', name: 'genderName'},
                    {display: '电话', name: 'phone'},
                    {display: '证件号', name: 'idno'},
                    {display: '年龄', name: 'age'},
                    {display: '入职日期', name: 'hireDate'},
                    {display: '状态', name: 'statusName'},
                    {display: '校区', name: 'school.name'},
                    {display: '部门', name: 'dept.name'}
                ],
                toolbar: {
                    items: [
                        { text: '增加', click: addEmployee, icon: 'add' },
                        { line: true },
                        { text: '修改', click: editEmployee, icon: 'modify' },
                        { line: true },
                        { text: '编辑用户角色', click: '', icon: 'modify' },
                        { line: true },
                        { text: '分配特殊权限', click: '', icon: 'modify' },
                        { line: true },
                        { text: '删除', click: deleteEmployee, icon: 'delete' }
                    ]
                }
            });

            //高级查询
            $("#btn_query").click(function() {
                // var currentPage = $("#currentPage").val();
                // var pageSize = $("#pageSize").val();
                var keyword = $("#keyword").val();
                var schoolId = $("#school_list").val();
                var deptId = $("#dept_list").val();
                grid.set({
                    url: '/employee/getEmployeeData.do',
                    //以下设置字段名，为了跟PageInfo的字段名相同才能实现分页
                    root:'list',
                    record:'total',
                    pageParmName:'currentPage',
                    pagesizeParmName:'pageSize',
                    dataAction: 'server',
                    //这样提交高级查询参数
                    parms: {keyword:keyword,schoolId:schoolId,deptId:deptId}

                });
                //grid.loadData();
            });

        });

        //新增员工
        function addEmployee() {
            window.parent.fn_addTabItem("addEmp","新增员工信息","/employee/toInputEmployee.do");
        }

        //编辑员工信息
        function editEmployee() {
            var rows = grid.getSelectedRows();
            if(rows == null || rows == "undefined" || rows.length == 0){
                $.ligerDialog.warn("请选择要修改的信息");
            }else if(rows.length > 1){
                $.ligerDialog.warn("不支持批量修改");
            }else{
                var id = rows[0].id;
                window.parent.fn_addTabItem("editEmp","修改员工信息","/employee/toInputEmployee.do?id=" + id);
            }
        }

        function deleteEmployee() {
            var rows = grid.getSelectedRows();
            if(rows == null || rows == "undefined" || rows.length == 0){
                $.ligerDialog.warn("请选择要删除的数据");
            }else{
                $.ligerDialog.confirm('确定要删除选中的数据吗？删除后不可恢复', function (yes) {
                    if(yes){
                        //注意着条语句用来处理数组的中括号问题的，不然会导致后台接收数组为空；
                        $.ajaxSettings.traditional=true;
                        var ids = [];
                        $.each(rows,function (index, value) {
                            ids[index] = value.id;
                        });
                        $.post("",{ids:ids},function (result) {
                            if(result.success){
                                $.ligerDialog.success("删除成功","提示",function () {
                                    window.location.reload();
                                })
                            }else {
                                $.ligerDialog.error(result.msg);
                            }
                        });
                    }
                });
            }
        }
        var schools = ${(schools)!};
        var depts = ${(depts)!};
        //二级联动，修改部门下拉列表
        function changeDeptSelect() {
            var schoolId = $("#school_list").val();
            if(schoolId == -1){
                renderOptions("dept_list",depts);
            }else{
                var school_dept;
                for(i =0; i < schools.length; i++){
                    if(schoolId == schools[i].id){
                        school_dept = schools[i].depts;
                        break;
                    }
                }
                renderOptions("dept_list",school_dept);
            }

        }

        //初始化渲染下拉列表(全部数据)
        $(function () {
            renderOptions("dept_list",depts);
            renderOptions("school_list",schools);
        });

        //渲染下拉列表选项
        function renderOptions(target, value) {
            var options = "<option value='-1'>全部</option>";
            for(i = 0; i < value.length; i++){
                options = options + "<option value='" + value[i].id + "'>" + value[i].name + "</option>";
            }
            $("#" + target + " option").remove();
            $("#" + target).append(options);
        }
        

    </script>
</head>
<body style="overflow-x:hidden; padding:2px;">
    <#--可以写一些表头的内容-->
    <div id="query_div">
        <!--高级查询--->
        <form class="form-inline" id="searchForm">
            <#--<input type="hidden" name="currentPage" id="currentPage" value="1">-->
            <#--<input type="hidden" name="pageSize" id="pageSize" value="20">-->
            <div class="form-group">
                <label>关键字:</label>
                <input type="text" class="form-control input-sm" name="keyword" id="keyword"
                       placeholder="请输入姓名/电话">
            </div>
            <div class="form-group">
                <label>校区:</label>
                <select class="form-control input-sm" name="schoolId" id="school_list" onchange="changeDeptSelect();">
                    <#--<option value="-1">全部</option>-->
                        <#--<#list (schools)! as sch>
                            <option value="${(sch.id)!}">${(sch.name)!}</option>
                        </#list>-->
                </select>
            </div>
            <div class="form-group">
                <label>部门:</label>
                <select class="form-control input-sm" name="deptId" id="dept_list">
                    <#--<option value="-1">全部</option>-->
                        <#--<#list (depts)! as d>
                            <option value="${(d.id)!}">${(d.name)!}</option>
                        </#list>-->
                </select>
            </div>
            <button type="button" id="btn_query" class="btn btn-info btn-sm">
                <span class="glyphicon glyphicon-search"></span> 查询
            </button>
        </form>
    </div>
    <div id="department_msg">
        <#--这里是数据表格-->
    </div>

</body>
</html>